﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.IO;
using TestCenter.Basics;
using TestCenter.Fit;

namespace TestCenter
{
	class Program
	{
		static void Main(string[] args)
		{
			string name = args.Length > 0 ? args[0].ToLower() : "fit";
			Console.WriteLine(typeof(StringTest));
			TestBase tb = null;
			switch (name)
			{
				case "menu":
					ShowMenu();
					break;
				case "delegate":
					tb = new Delegate.Delegate();
					break;
				case "null":
					tb = new NullTest();
					break;
				case "fit":
					tb = new FitComputation();
					break;
				default:
					Console.WriteLine("For test only.");
					break;
			}

			tb?.Test();

			Console.Read();
		}

		private static void ShowMenu()
		{
			string exefile = Path.GetFullPath("TestCetner.exe");
			if (!File.Exists(exefile))
			{
				Console.WriteLine($"File '{exefile}' does not exist.");
				return;
			}
			Assembly asm = Assembly.LoadFile(exefile);
			foreach (var type in asm.GetTypes())
			{
				object obj = Activator.CreateInstance(type);
				Console.WriteLine(obj.ToString() + "\t" + (obj is TestBase));
				if (Activator.CreateInstance(type) is TestBase tb)
				{
					Console.WriteLine($"{type.Name}\n\t{tb.Description()}");
				}
			}
		}
	}
}
